import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15

MainView {
    id: root
Component.onCompleted:
{
}
    DateTimeDialog{
            id: dlg
            text: qsTr("日期")
            //type: "Time"
            onAccepted: {
                startDate.text=getText("yyyy-MM-dd hh:mm:ss")
                if (typeof rectangle !== 'undefined' && typeof rectangle.resetScreenSaverTimer === 'function') {
                    rectangle.resetScreenSaverTimer();
                }         
            }
            onRejected: {
                // 取消时也复位屏幕保护定时器
                if (typeof rectangle !== 'undefined' && typeof rectangle.resetScreenSaverTimer === 'function') {
                    rectangle.resetScreenSaverTimer();
                }
            }
        }
    Button
    {
        id:startDate
        anchors.centerIn: parent
        width: 310
        height: 80
        text:Qt.formatDateTime(new Date(), "yyyy-MM-dd hh:mm:ss")
        font.pixelSize: 25
            //Qt.formatDateTime(new Date(), "yyyy-MM-dd")
        background:
            Rectangle{
            border.width: 0
            color: "#7584C2"
                //startDate.down?"#388C8C":
                }
        onClicked: {
            if (typeof rectangle !== 'undefined' && typeof rectangle.stopScreenSaverTimer === 'function') {
                rectangle.stopScreenSaverTimer();
            }             
            dlg.open()
            dlg.exec(startDate.text)
        }
        palette.buttonText: "white"
    }

Button
{
    id:btnDateOK
    x: 572
    y: 281
    //x: 675
    //y: 20
    width: 100
    height: 100
    background: Rectangle{
        border.width: 0
        color: "#C070B0"
            }

    text: qsTr("确定")
    font.pixelSize: 25
    palette.buttonText: "white"
    onClicked: {
        if(loaderText.visible)
        {
            return;
        }
        loaderText.visible=true;
        funcTimer.start();

    }
}
Button
{
    id:btnReturn
    x: 688
    y: 281
    //x: 675
    //y: 20
    width: 100
    height: 100
    background: Rectangle{
        border.width: 0
        color: "#B0B0D0"
            }

    text: qsTr("返回")
    font.pixelSize: 25
    palette.buttonText: "white"
    onClicked: {
        //rectangle.selectedView = 4
        bottomBar.selected=4
//                myLoader.visible=false;
//                myLoader.visible=true
        myLoader.source="SettingsPanel.qml"
        //destroy()
    }
}
Timer {
    id:funcTimer
            running: false
            repeat: false
            interval:100
            onTriggered: {
                mymodbus.correctTime(startDate.text);
                loaderText.visible=false;
            }
        }
    MyBuzyIndicator{
        anchors.centerIn: parent
        id: dataLoader
        visible:false
        //anchors.verticalCenterOffset: 3
        //anchors.horizontalCenterOffset: 22
    }
}

